/*
 * Copyright (C) 2013 The i18nCTS Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.i18nCTS.view;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.googlecode.i18nCTS.R;

public class DateUtilsListViewSectionFragment extends ListFragment {
	static final String[] DATE_LIST = new String[] { 
		"Single Date", 
		"Range (diff time)",
		"Range (same month)", 
		"Range (diff month)",
		"Range (same month/diff year)", 
		"Range (diff month/diff year)",
		"Noon and Midnight",
		"Date and Weekday",
		"Weekday and Time"
		};
	
	private static final String TAG = "I18nCTS_" + DateUtilsListViewSectionFragment.class.getSimpleName();
	public static final String ARG_SECTION_NUMBER = "section_number";
	Context mContext;

	public DateUtilsListViewSectionFragment() {
		Log.d(TAG, "ctr");
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// Create a new TextView and set its text to the fragment's section
		// number argument value.
		mContext = getActivity();
		
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(inflater.getContext(), 
				android.R.layout.simple_list_item_1, DATE_LIST);
        setListAdapter(adapter);
        
		View listView = inflater.inflate(R.layout.list_dateutils, null);
				
		return listView;
	}
	
	@Override
	public void onListItemClick(ListView l, View v, int position, long id)
	{
		super.onListItemClick(l, v, position, id);
		
		Fragment fragment = null;
        switch (position) {
	    	case 0: // single date
	    		fragment = new DateUtilsSingleDateSectionFragment();
				break;
				
	    	case 1: // range same month
	    		fragment = new DateUtilsRangeDiffTimeSectionFragment();
				break;
				
	    	case 2: // range same month
	    		fragment = new DateUtilsRangeSameMonthSectionFragment();
				break;
	
	    	case 3:		// Range date: different month
	    		fragment = new DateUtilsRangeDiffMonthSectionFragment();
				break;
				
	    	case 4:        // Range date: same month different year
	    		fragment = new DateUtilsRangeSameMonthDiffYearSectionFragment();
				break;
				
	    	case 5:        // Range date: different month different year
	    		fragment = new DateUtilsRangeDiffMonthDiffYearSectionFragment();
				break;
		
	    	case 6:		// noon midnight
	    		fragment = new DateUtilsNoonMidnightSectionFragment();
	    		break;
	    		
	    	case 7:		// weekday
	    		fragment = new DateUtilsDayWeekdaySectionFragment();
	    		break;
	
	    	case 8:		// weekday and Time
	    		fragment = new DateUtilsWeekdayTimeSectionFragment();
	    		break;
        }
		getActivity().getSupportFragmentManager().beginTransaction()
		.replace(R.id.container, fragment).commit();

	}

}